package com.tvein.sanguo.action.controller.login
{
	//flash
	import flash.display.DisplayObject;
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.action.view.ActionMediator;
	import com.tvein.sanguo.action.model.SystemProxy;
	import com.tvein.sanguo.swc.action.login.LoginEnter;
	import com.tvein.sanguo.swc.action.login.LoginForget;
	import com.tvein.sanguo.swc.action.login.LoginCreate;
//
	public class ActionLogin extends SimpleFabricationCommand implements ICommand
	{
		private var actionMediator:ActionMediator;
		private var systemData:SystemProxy;
		
		override public function execute(notification:INotification) : void
		{
			actionMediator = facade.retrieveMediator(ActionMediator.NAME) as ActionMediator;
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			
			clearChild();
			
			var params:Object = new Object();
			
			switch(notification.getBody())
			{
				case "enter":
					var loginEnter:LoginEnter = new LoginEnter();
					actionMediator.action.addChild(loginEnter);
					loginEnter.name = "LoginEnter";

					params.Volume = systemData.effectVol;
					loginEnter.console("setEffect", params);
					
					loginEnter.addEventListener("Login-Enter", actionMediator._handleEvents);
					
					break;
				case "forget":
					var loginForget:LoginForget = new LoginForget();
					actionMediator.action.addChild(loginForget);
					loginForget.name = "LoginForget";
					
					params.Volume = systemData.effectVol;
					loginForget.console("setEffect", params);
					
					loginForget.addEventListener("Login-Forget", actionMediator._handleEvents);
					
					break;
				case "create":
					var loginCreate:LoginCreate = new LoginCreate();
					actionMediator.action.addChild(loginCreate);
					loginCreate.name = "LoginCreate";
					
					params.Volume = systemData.effectVol;
					loginCreate.console("setEffect", params);
					
					loginCreate.addEventListener("Login-Create", actionMediator._handleEvents);
					
					break;
			}
		}
		
		private function clearChild():void
		{
			for (var i:int = actionMediator.action.numChildren - 1; i >= 0; i--)
			{
				actionMediator.action.removeChildAt(0); 
			}
		}
	}
}